# -*- coding: utf-8 -*-
from django import template
from payments.utils.d2w import d2w

register = template.Library()

@register.filter(name='lv2w')
def lv2w(amount):
    amount = str(amount)
    out = ""
    if not "." in amount:
        out = d2w(int(amount)) + " лева"
    else:
        lv, st = amount.split(".")
        out = d2w(int(lv)).strip() + " лева"
        if int(st):
            out += " и " + d2w("%02d" % int(st)).strip() + " стотинки"
    return out.replace("  ", " ").strip()

@register.filter(name='zeropad')
def zeropad(value, ndigits):
    d = str(value)
    ndigits = int(ndigits)
    if len(d) >= ndigits:
        return d
    return "0" * (ndigits-len(d)) + d
